package com.xzr3;

abstract class Employee {
    public abstract double earnings();
}
class YearWorker extends Employee {
    @Override
    public double earnings() {
        double YearWorker_mon = Math.random()*10000;
        return YearWorker_mon;
    }

}
class MonthWorker extends Employee {
    @Override
    public double earnings() {
        double MonthWorker_mon = Math.random()*5000;
        return MonthWorker_mon;
    }

}
class WeekWorker extends Employee {
    @Override
    public double earnings() {
        double WeekWorker_mon = Math.random()*3000;
        return WeekWorker_mon;
    }

}
class Company {
    Employee[] employee;
    double salaries=0;
    Company(Employee[] employee) {
        this.employee=employee;
    }
    public double salariesPay() {
        salaries=0;
       //计算salaries。
        for(int i = 0; i < employee.length; i++) {
            salaries += employee[i].earnings();
        }
        return salaries;
    }
}
public class CompanySalary {
    public static void main(String args[]) {
        Employee [] employee=new Employee[29]; //公司有29名雇员
        for(int i=0;i<employee.length;i++) {   //雇员简单地分成三类
            if(i%3==0)
                employee[i]=new WeekWorker();
            else if(i%3==1)
                employee[i]=new MonthWorker();
            else if(i%3==2)
                employee[i]=new YearWorker();
        }
        Company company=new Company(employee);
        System.out.println("公司薪水总额:"+company.salariesPay()+"元");
    }
}
